trigger OORRestricSameMonthYear on Booking_Dates__c (before insert,before update) {

      //Trigger Name: OORRestricSameMonthYear
      //Author: Accenture IDC
      //Purpose: Restrict User from Saving more then one Booking Closing Record for same month in that Year.
      //Date: 13/10/2011
      
      Set<String> month = New Set<String>();
      Set<String> year= New Set<String>();
         
          for(Booking_Dates__c booking:Trigger.New){
                  if(Trigger.ISINSERT ||(Trigger.ISUPDATE &&( booking.Booking_Closing_Month__c!=Trigger.OldMap.get(booking.Id).Booking_Closing_Month__c || booking.Booking_Closing_Year1__c!=Trigger.OldMap.get(booking.Id).Booking_Closing_Year1__c ))){
                   month.add(booking.Booking_Closing_Month__c);
                   year.add(booking.Booking_Closing_Year1__c);}
                   
             }
      List<Booking_Dates__c> bookingList=[Select Id from Booking_Dates__c where Booking_Closing_Month__c IN:month AND Booking_Closing_Year1__c IN:year ];
      for(Booking_Dates__c booking:Trigger.New){
              if(bookingList.Size()>0){
              Trigger.New[0].addError('Please Check the Month and Year.You Can only create one Booking record for a Month in that Year');
            }
  
        }
     }